private void CheckNewlyAddedControlMessages(Control control) { if (control.ScreenRect.Contains(CurrentMousePos)) { control.OnMouseEnter(); CurrentUnderMouse = control; } }
private bool CheckNewlyAddedControlPosition(Control control) { Point newPos = AutoPosition(control.ScreenPosition, control.Size); if (newPos == control.ScreenPosition) { return true; } control.ScreenPosition = newPos; return false; }
// ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method propagates messages to children controls and managers. Override to /// add custom handling. /// </summary> protected internal override void OnMouseButtonDown(MouseData mouseData) { base.OnMouseButtonDown(mouseData); foreach (Manager m in managerList) { m.OnMouseButtonDown(mouseData); } // If applicable, forward MouseDown and Select to child control if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseButtonDown(mouseData); LastLBDown = CurrentUnderMouse; } // Check to see if a control looses KBFocus if user hit any mouse button outside current focused control if (CurrentKeyboardFocus != null) { if (CurrentKeyboardFocus != CurrentUnderMouse) { CurrentKeyboardFocus.OnReleaseKeyboardFocus(); CurrentKeyboardFocus = null; } } // Give KBFocus to child on left button down, if applicable if (CurrentUnderMouse != null && CurrentUnderMouse.CanHaveKeyboardFocus && CurrentUnderMouse.HasKeyboardFocus == false && mouseData.MouseButton == MouseButton.LeftButton && CurrentUnderMouse.IsActive) { CurrentKeyboardFocus = CurrentUnderMouse; CurrentKeyboardFocus.OnTakeKeyboardFocus(); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method propagates messages to children controls and managers. Override to /// add custom handling. /// </summary> protected internal override void OnMouseButtonUp(MouseData mouseData) { base.OnMouseButtonUp(mouseData); foreach (Manager m in managerList) { m.OnMouseButtonUp(mouseData); } if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseButtonUp(mouseData); } LastLBDown = null; }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Remove the provided control from the window. /// </summary> /// <param name="control"></param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="control"/> /// is null.</exception> public void RemoveControl(Control control) { if (control == null) { throw new ArgumentNullException("control"); } if (controlList.Contains(control)) { controlRemoveList.Add(control); } if (controlAddList.Contains(control)) { controlAddList.Remove(control); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Forces the keyboard focus to the given control, sending a TakeKeyboardFocus /// message to the specified control. If a control currently has the /// keyboard focus, that control will receive a ReleaseKeyboardFocus message. /// </summary> public void TakeKeyboard(Control control) { if (control == null) { throw new ArgumentNullException("control"); } if (control != CurrentKeyboardFocus) { control.OnTakeKeyboardFocus(); if (CurrentKeyboardFocus != null) { CurrentKeyboardFocus.OnReleaseKeyboardFocus(); } CurrentKeyboardFocus = control; } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Release the keyboard focus from the provided control. The control will receive /// a ReleaseKB message (and raise the related RelaseKeyboardEvent) /// </summary> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="control"/> /// is null.</exception> public void ReleaseKeyboard(Control control) { if (control == null) { throw new ArgumentNullException("control"); } if (control == CurrentKeyboardFocus) { control.OnReleaseKeyboardFocus(); CurrentKeyboardFocus = null; } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Moves the specified control to the top of the draw order. Controls on top /// are drawn over lower controls. /// </summary> /// <param name="control"></param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="control"/> /// is null.</exception> public void MoveToTop(Control control) { if (control == null) { throw new ArgumentNullException("control"); } if(ContainsControl(control)) { controlList.Remove(control); controlList.Add(control); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Moves specified control to the bottom of the draw order. Controls on bottom /// are drawn first (covered up by higher controls). /// </summary> /// <param name="control"></param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="control"/> /// is null.</exception> public void MoveToBottom(Control control) { if (control == null) { throw new ArgumentNullException("control"); } if(ContainsControl(control)) { controlList.Remove(control); controlList.Insert(0, control); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Returns true if Window currently contains the specified control. /// </summary> /// <param name="control"></param> /// <returns></returns> public bool ContainsControl(Control control) { return ControlList.Contains(control); }
/// <summary> /// Adds a control instance to this window. All controls must be reference-unique, or this /// method will throw an ArgumentException. This method will also throw an ArgumentExeption /// if the control is too large to fit on the screen. A newly added control may receive /// a MouseEnter message if the mouse is within it's region, and will always receive a /// SettingUp message if it hasn't received one previously. /// </summary> /// <param name="control"></param> /// <returns></returns> /// <exception cref="System.ArgumentException">Thrown when the specified <paramref name="control"/> /// is already contained by this window.</exception> public bool AddControl(Control control) { if (ContainsControl(control) || controlAddList.Contains(control)) { throw new ArgumentException("CurrentWindow already contians an instance of this control"); } this.controlAddList.Add(control); bool atRequestedPos = CheckNewlyAddedControlPosition(control); if (!atRequestedPos) { if (!ScreenRect.Contains(control.ScreenRect.UpperLeft) || !ScreenRect.Contains(control.ScreenRect.LowerRight)) { throw new ArgumentException("The specified control is too large to fit on the screen."); } } CheckNewlyAddedControlMessages(control); control.ParentWindow = this; control.Pigments = new PigmentMap(Pigments, control.PigmentOverrides); if (!control.isSetup) { control.OnSettingUp(); } return atRequestedPos; }