Ejemplo n.º 1
0
        /// <summary>
        /// Adds a handler-based event delegate with the specified key
        /// </summary>
        /// <remarks>
        /// This should be called in an event's add accessor.
        /// This is used for any event that should be triggered by the platform handler.
        /// This will call <see cref="M:Eto.Widget.IHandler.HandleEvent(string,bool)"/> with the specified <paramref name="key"/> for the
        /// first subscription to the event.
        ///
        /// You can use any subclass of <see cref="System.EventArgs"/> for the type of event handler
        ///
        /// To trigger the event, use <see cref="TriggerEvent{T}"/>
        /// </remarks>
        /// <example>
        /// Example implementation of a handler-triggered event
        /// <code>
        ///     public const string MySomethingEvent = "MyControl.MySomething";
        ///
        ///     public event EventHandler&lt;EventArgs&gt; MySomething
        ///     {
        ///         add { Properties.AddHandlerEvent(MySomethingEvent, value); }
        ///         remove { Properties.RemoveHandlerEvent(MySomethingEvent, value); }
        ///     }
        /// </code>
        /// </example>
        /// <param name="key">Key of the event to add to</param>
        /// <param name="value">Delegate to add to the event</param>
        public void AddHandlerEvent(string key, Delegate value)
        {
            var parentWidget = Parent as Widget;

            if (parentWidget == null)
            {
                throw new InvalidOperationException("Parent must subclass Widget");
            }
            object existingDelegate;

            if (TryGetValue(key, out existingDelegate))
            {
                this[key] = Delegate.Combine((Delegate)existingDelegate, value);
            }
            else
            {
                if (!EventLookup.IsDefault(parentWidget, key))
                {
                    Add(key, value);
                    parentWidget.HandleEvent(key);
                }
                else
                {
                    Add(key, value);
                }
            }
        }
Ejemplo n.º 2
0
Archivo: Widget.cs Proyecto: zzlvff/Eto
        /// <summary>
        /// Initializes the widget handler
        /// </summary>
        /// <remarks>
        /// This is typically called from the constructor after all of the logic is completed to construct
        /// the object.
        ///
        /// If your handler interface has the <see cref="AutoInitializeAttribute"/> set to false, then you are responsible
        /// for calling this method in your constructor after calling the creation method on your custom handler.
        /// </remarks>
        protected void Initialize()
        {
            var handler = WidgetHandler;

            if (handler != null)
            {
                handler.Initialize();
            }
            EventLookup.HookupEvents(this);
            Platform.Instance.TriggerWidgetCreated(new WidgetCreatedEventArgs(this));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the widget handler
        /// </summary>
        /// <remarks>
        /// This is typically called from the constructor after all of the logic is completed to construct
        /// the object.
        ///
        /// If your handler interface has the <see cref="AutoInitializeAttribute"/> set to false, then you are responsible
        /// for calling this method in your constructor after calling the creation method on your custom handler.
        /// </remarks>
        protected void Initialize()
        {
            var handler = WidgetHandler;

            if (handler != null)
            {
                handler.Initialize();
            }
            Eto.Style.OnStyleWidgetDefaults(this);
            EventLookup.HookupEvents(this);
        }
Ejemplo n.º 4
0
        public void AddHandlerEvent(string key, Delegate value)
        {
            object existingDelegate;

            if (TryGetValue(key, out existingDelegate))
            {
                this[key] = Delegate.Combine((Delegate)existingDelegate, value);
            }
            else
            {
                if (!EventLookup.IsDefault(Parent, key))
                {
                    Parent.HandleDefaultEvents(key);
                }
                Add(key, value);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called to handle a specific event
        /// </summary>
        /// <remarks>
        /// Most events are late bound by this method. Instead of wiring all events, this
        /// will be called with an event string that is defined by the control.
        ///
        /// This is called automatically when attaching to events, but must be called manually
        /// when users of the control only override the event's On... method.
        ///
        /// Override the <see cref="AttachEvent"/> to attach your events
        /// </remarks>
        /// <seealso cref="AttachEvent"/>
        /// <param name="id">ID of the event to handle</param>
        /// <param name="defaultEvent">True if the event is default (e.g. overridden or via an event handler subscription)</param>
        public void HandleEvent(string id, bool defaultEvent = false)
        {
            var instanceId = id + InstanceEventSuffix;

            if (Widget.Properties.ContainsKey(instanceId))
            {
                return;
            }

            if (defaultEvent)
            {
                AttachEvent(id);
            }
            else if (!EventLookup.IsDefault(Widget, id))
            {
                Widget.Properties.Add(instanceId, true);
                AttachEvent(id);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds a handler-based event delegate with the specified key
        /// </summary>
        /// <remarks>
        /// This should be called in an event's add accessor.
        /// This is used for any event that should be triggered by the platform handler.
        /// This will call <see cref="M:Eto.Widget.IHandler.HandleEvent(string,bool)"/> with the specified <paramref name="key"/> for the
        /// first subscription to the event.
        ///
        /// You can use any subclass of <see cref="System.EventArgs"/> for the type of event handler
        ///
        /// To trigger the event, use <see cref="TriggerEvent{T}"/>
        /// </remarks>
        /// <example>
        /// Example implementation of a handler-triggered event
        /// <code>
        ///     public const string MySomethingEvent = "MyControl.MySomething";
        ///
        ///     public event EventHandler&lt;EventArgs&gt; MySomething
        ///     {
        ///         add { Properties.AddHandlerEvent(MySomethingEvent, value); }
        ///         remove { Properties.RemoveHandlerEvent(MySomethingEvent, value); }
        ///     }
        /// </code>
        /// </example>
        /// <param name="key">Key of the event to add to</param>
        /// <param name="value">Delegate to add to the event</param>
        public void AddHandlerEvent(string key, Delegate value)
        {
            object existingDelegate;

            if (TryGetValue(key, out existingDelegate))
            {
                this[key] = Delegate.Combine((Delegate)existingDelegate, value);
            }
            else
            {
                if (!EventLookup.IsDefault(Parent, key))
                {
                    var handler = Parent.Handler as Widget.IHandler;
                    if (handler != null)
                    {
                        handler.HandleEvent(key);
                    }
                }
                Add(key, value);
            }
        }
Ejemplo n.º 7
0
Archivo: Widget.cs Proyecto: zzlvff/Eto
 /// <summary>
 /// Registers the event for overridding
 /// </summary>
 /// <remarks>
 /// This is used to register an event that will be automatically hooked up when a derived class overrides the
 /// event method.
 /// This should be called in the static constructor of your class.
 /// </remarks>
 /// <example>
 /// Shows a custom control with an event:
 /// <code>
 /// public class MyEtoControl : Eto.Forms.Control
 /// {
 ///     public const string MySomethingEvent = "MyEtoControl.MySomethingEvent";
 ///
 ///     public event EventHandler&lt;EventArgs&gt; MySomething
 ///     {
 ///         add { Properties.AddHandlerEvent(MySomethingEvent, value); }
 ///         remove { Properties.RemoveEvent(MySomethingEvent, value); }
 ///     }
 ///
 ///     protected virtual void OnMySomething(EventArgs e)
 ///     {
 ///         Properties.TriggerEvent(MySomethingEvent, this, e);
 ///     }
 ///
 ///     static MyEtoControl()
 ///     {
 ///         RegisterEvent&lt;MyEtoControl&gt;(c => c.OnMySomething(null), MySomethingEvent);
 ///     }
 /// }
 /// </code>
 /// </example>
 /// <param name="method">Expression to call the method that raises your event</param>
 /// <param name="identifier">Identifier of the event</param>
 /// <typeparam name="T">Your object type</typeparam>
 protected static void RegisterEvent <T>(Expression <Action <T> > method, string identifier)
 {
     EventLookup.Register(method, identifier);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Gets a value indicating that the specified event is handled
 /// </summary>
 /// <param name="id">Identifier of the event</param>
 /// <returns>True if the event is handled, otherwise false</returns>
 public bool IsEventHandled(string id)
 {
     return(Widget.Properties.ContainsKey(id) || EventLookup.IsDefault(Widget, id) || Widget.Properties.ContainsKey(id + InstanceEventSuffix));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes the widget handler
 /// </summary>
 /// <remarks>
 /// This is typically called from the constructor after all of the logic is completed to construct
 /// the object.
 ///
 /// If you pass false to the constructor's initialize property, you should call this manually in your constructor
 /// after all of its logic has finished.
 /// </remarks>
 protected new void Initialize()
 {
     base.Initialize();
     Eto.Style.OnStyleWidgetDefaults(this);
     EventLookup.HookupEvents(this);
 }