Example #1
0
        /// <summary>
        /// If possible, gives the focus to the specified widget.
        /// It's possible that the widget that owned previously the focus
        /// REFUSE to give the focus to the one you want to give it.
        /// It's also possible that the desired receiver REFUSES
        /// to get the focus.
        /// If you pass a null reference in focusReceiver, then no one
        /// widget will get the focus from this player.
        /// </summary>
        /// <param name="index">Associated player to the focus.</param>
        /// <param name="focusReceiver">New receiver of the focus.</param>
        /// <returns>True if the widget received the focus, false otherwise.</returns>
        public bool SetFocus(Widget focusReceiver)
        {
            FocusChangedEvent evt = new FocusChangedEvent(FocusChangedEvent.FocusStateChange.LostFocus);

            Widget oldFocusedWidget = myFocusedWidget;

            // the old owner of the focus can refuse the lost of the focus.
            if (oldFocusedWidget != null)
            {
                oldFocusedWidget.OnEvent(evt);

                if (evt.Accepted)
                {
                    oldFocusedWidget.OnFocusChangedEvent(evt);

                    if (evt.Accepted)
                        myFocusedWidget = null;
                }
            }

            // the old owner is ready to loose focus
            // or there is no old owner.
            if (evt.Accepted && focusReceiver != null)
            {
                if (HasFocus(focusReceiver) == false)
                {
                    // the focus receiver doesn't have the focus from another player.
                    evt.StateChange = FocusChangedEvent.FocusStateChange.GainedFocus;

                    focusReceiver.OnEvent(evt);

                    if (evt.Accepted)
                    {
                        focusReceiver.OnFocusChangedEvent(evt);
                        if (evt.Accepted)
                        {
                            //the widget has accepted the focus.
                            myFocusedWidget = focusReceiver;
                        }
                    }
                }
                else
                    evt.Accepted = false;//the receiver has the focus from another player.
            }

            return evt.Accepted;
        }
Example #2
0
 /// <summary>
 /// Raised when the widget can gain/lose the focus.
 /// </summary>
 /// <param name="focusEvent">raised event.</param>
 public virtual void OnFocusChangedEvent(FocusChangedEvent focusEvent)
 {
 }