예제 #1
0
 internal void ResetActiveAndFocusedControlsRecursive()
 {
     if (activeControl is ContainerControl)
     {
         ((ContainerControl)activeControl).ResetActiveAndFocusedControlsRecursive();
     }
     activeControl  = null;
     focusedControl = null;
 }
예제 #2
0
        /// <internalonly/>
        /// <devdoc>
        ///     Used for UserControls - checks if the control
        ///     has a focusable control inside or not
        /// </devdoc>
        internal bool HasFocusableChild()
        {
            ControlViewModel ctl = null;

            do
            {
                ctl = GetNextControl(ctl, true);
                if (ctl != null &&
                    ctl.CanSelect &&
                    ctl.TabStop)
                {
                    break;
                }
            } while (ctl != null);
            return(ctl != null);
        }
예제 #3
0
        public static bool HasFocusableChild(this IUserControl userControl)
        {
            ControlViewModel ctl = null;

            do
            {
                ctl = ((ControlViewModel)userControl).GetNextControl(ctl, true);
                if (ctl != null &&
                    ctl.CanSelect &&
                    ctl.TabStop)
                {
                    break;
                }
            } while (ctl != null);
            return(ctl != null);
        }
예제 #4
0
 /// <summary>
 /// Retrieves a value indicating whether the specified control is a child of the control.
 /// </summary>
 ///
 /// <returns>
 /// true if the specified control is a child of the control; otherwise, false.
 /// </returns>
 /// <param name="ctl">The <see cref="T:System.Windows.Forms.Control"/> to evaluate. </param><filterpriority>1</filterpriority>
 public bool Contains(ControlViewModel ctl)
 {
     while (ctl != null)
     {
         ctl = ctl.Parent;
         if (ctl == null)
         {
             return(false);
         }
         if (ctl == this)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #5
0
        internal bool ValidateInternal(bool checkAutoValidate, out bool validatedControlAllowsFocusChange)
        {
            validatedControlAllowsFocusChange = false;

            if (this.AutoValidate == AutoValidate.EnablePreventFocusChange ||
                (activeControl != null && activeControl.CausesValidation))
            {
                if (unvalidatedControl == null)
                {
                    if (focusedControl is ContainerControl && focusedControl.CausesValidation)
                    {
                        ContainerControl c = (ContainerControl)focusedControl;
                        if (!c.ValidateInternal(checkAutoValidate, out validatedControlAllowsFocusChange))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        unvalidatedControl = focusedControl;
                    }
                }

                // Should we force focus to stay on same control if there is a validation error?
                bool preventFocusChangeOnError = true;

                ControlViewModel controlToValidate = unvalidatedControl != null ? unvalidatedControl : focusedControl;

                if (controlToValidate != null)
                {
                    // Get the effective AutoValidate mode for unvalidated control (based on its container control)
                    AutoValidate autoValidateMode = ControlViewModel.GetAutoValidateForControl(controlToValidate);

                    // Auto-validate has been turned off in container of unvalidated control - stop now
                    if (checkAutoValidate && autoValidateMode == AutoValidate.Disable)
                    {
                        return(true);
                    }
                    preventFocusChangeOnError         = (autoValidateMode == AutoValidate.EnablePreventFocusChange);
                    validatedControlAllowsFocusChange = (autoValidateMode == AutoValidate.EnableAllowFocusChange);
                }

                return(ValidateThroughAncestor(null, preventFocusChangeOnError));
            }
            return(true);
        }
예제 #6
0
        /// <devdoc>
        ///     Unsafe version of SetActiveControl - Use with caution!
        /// </devdoc>
        internal void SetActiveControlInternal(ControlViewModel value)
        {
            if (activeControl != value || (value != null && !value.Focused))
            {
                if (value != null && !Contains(value))
                {
                    throw new ArgumentException(UpgradeHelpers.Helpers.SafeNativeMethods.SR.GetString(UpgradeHelpers.Helpers.SafeNativeMethods.SR.CannotActivateControl));
                }

                bool             ret;
                ContainerControl cc = this;

                if (value != null && value.ParentInternal != null)
                {
                    cc = (value.ParentInternal.GetContainerControlInternal()) as ContainerControl;
                }
                if (cc != null)
                {
                    // Call to the recursive function that corrects the chain
                    // of active controls
                    ret = cc.ActivateControlInternal(value, false);
                }
                else
                {
                    ret = AssignActiveControlInternal(value);
                }

                if (cc != null && ret)
                {
                    ContainerControl ccAncestor = this;
                    while (ccAncestor.ParentInternal != null &&
                           ccAncestor.ParentInternal.GetContainerControlInternal() is ContainerControl)
                    {
                        ccAncestor = ccAncestor.ParentInternal.GetContainerControlInternal() as ContainerControl;
                    }

                    if (ccAncestor.ContainsFocus &&
                        (value == null ||
                         !(value is IUserControl) ||
                         (value is IUserControl && !((IUserControl)value).HasFocusableChild())))
                    {
                        cc.FocusActiveControlInternal();
                    }
                }
            }
        }
 public void ScrollControlIntoView(ControlViewModel activeControl)
 {
     if (!this.AutoScroll)
     {
         return;
     }
     if (activeControl.UniqueID != "" && activeControl.UniqueID.Split('#').Length > 0)
     {
         this.ScrollToElemID = activeControl.UniqueID.Split('#')[0];
     }
     //Rectangle clientRectangle = this.ClientRectangle;
     //if (!this.IsDescendant(activeControl) || !this.AutoScroll || !this.HScroll && !this.VScroll || (activeControl == null || clientRectangle.Width <= 0 || clientRectangle.Height <= 0))
     //    return;
     //Point point = this.ScrollToControl(activeControl);
     //this.SetScrollState(8, false);
     //this.SetDisplayRectLocation(point.X, point.Y);
     //this.SyncScrollbars(true);
 }
예제 #8
0
 private bool ActivateControlInternal(ControlViewModel value, bool p)
 {
     throw new NotImplementedException();
 }
예제 #9
0
        private bool ValidateThroughAncestor(ControlViewModel ancestorControl, bool preventFocusChangeOnError)
        {
            if (ancestorControl == null)
            {
                ancestorControl = this;
            }
            if (state[stateValidating])
            {
                return(false);
            }
            if (unvalidatedControl == null)
            {
                unvalidatedControl = focusedControl;
            }
            //return true for a Container Control with no controls to validate....
            //
            if (unvalidatedControl == null)
            {
                return(true);
            }
            if (!ancestorControl.IsDescendant(unvalidatedControl))
            {
                return(false);
            }

            this.state[stateValidating] = true;
            bool cancel = false;

            ControlViewModel currentActiveControl     = activeControl;
            ControlViewModel currentValidatingControl = unvalidatedControl;

            if (currentActiveControl != null)
            {
                currentActiveControl.ValidationCancelled = false;
                if (currentActiveControl is ContainerControl)
                {
                    ContainerControl currentActiveContainerControl = currentActiveControl as ContainerControl;

                    currentActiveContainerControl.ResetValidationFlag();
                }
            }
            try
            {
                while (currentValidatingControl != null && currentValidatingControl != ancestorControl)
                {
                    try
                    {
                        cancel = currentValidatingControl.PerformControlValidation(false);
                    }
                    catch
                    {
                        cancel = true;
                        throw;
                    }

                    if (cancel)
                    {
                        break;
                    }

                    currentValidatingControl = currentValidatingControl.ParentInternal;
                }

                if (cancel && preventFocusChangeOnError)
                {
                    if (unvalidatedControl == null && currentValidatingControl != null &&
                        ancestorControl.IsDescendant(currentValidatingControl))
                    {
                        unvalidatedControl = currentValidatingControl;
                    }
                    // This bit 'marks' the control that was going to get the focus, so that it will ignore any pending
                    // mouse or key events. Otherwise it would still perform its default 'click' action or whatever.
                    if (currentActiveControl == activeControl)
                    {
                        if (currentActiveControl != null)
                        {
                            CancelEventArgs ev = new CancelEventArgs();
                            ev.Cancel = true;
                            currentActiveControl.NotifyValidationResult(currentValidatingControl, ev);
                            if (currentActiveControl is ContainerControl)
                            {
                                ContainerControl currentActiveContainerControl = currentActiveControl as ContainerControl;
                                if (currentActiveContainerControl.focusedControl != null)
                                {
                                    currentActiveContainerControl.focusedControl.ValidationCancelled = true;
                                }
                                currentActiveContainerControl.ResetActiveAndFocusedControlsRecursive();
                            }
                        }
                    }
                    // This bit forces the focus to move back to the invalid control
                    SetActiveControlInternal(unvalidatedControl);
                }
            }
            finally
            {
                unvalidatedControl     = null;
                state[stateValidating] = false;
            }

            return(!cancel);
        }
 protected virtual Point ScrollToControl(ControlViewModel activeControl)
 {
     throw new NotImplementedException();
 }
예제 #11
0
 /// <summary>
 /// Activates the next control.
 /// </summary>
 /// <param name="ctl"> The Control at which to start the search.</param>
 /// <param name="forward"> true to move forward in the tab order; false to move backward in the tab order.</param>
 /// <param name="tabStopOnly"> true to ignore the controls with the TabStop property set to false; otherwise, false.</param>
 /// <param name="nested"> true to include nested (children of child controls) child controls; otherwise, false.</param>
 /// <param name="wrap"> true to continue searching from the first control in the tab order after the last control has been reached; otherwise, false.</param>
 /// <maps>SelectNextControl</maps>
 public bool SelectNextControl(ControlViewModel ctl, bool forward, bool tabStopOnly, bool nested, bool wrap)
 {
     return(false);
 }
예제 #12
0
 internal void NotifyValidationResult(ControlViewModel currentValidatingControl, System.ComponentModel.CancelEventArgs ev)
 {
     throw new NotImplementedException();
 }
예제 #13
0
 internal bool IsDescendant(ControlViewModel unvalidatedControl)
 {
     throw new NotImplementedException();
 }
예제 #14
0
 protected static AutoValidate GetAutoValidateForControl(ControlViewModel controlToValidate)
 {
     return(AutoValidate.EnableAllowFocusChange); //KMASIS
 }
예제 #15
0
 protected virtual void InvokePaintBackground(ControlViewModel c, PaintEventArgs e)
 {
     // throw new NotImplementedException();
 }