Example #1
0
        // Static Create method called by the event tracker system
        internal static void RaiseEvents(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild)
        {
            if (idObject != NativeMethods.OBJID_VSCROLL && idObject != NativeMethods.OBJID_HSCROLL)
            {
                ProxySimple el;
                if (IsInsideOfIPAddress(hwnd))
                {
                    el = new ByteEditBoxOverride(hwnd, idChild);
                }
                else
                {
                    el = new WindowsEditBox(hwnd, null, 0);

                    // If this is an Edit control inside of a Microsoft Spinner, need to treat the property
                    // changes for as property changes on the whole Microsoft Spinner, not on the element
                    // of the Microsoft Spinner.  Microsoft Spinner raise WinEvents on the Edit portion of
                    // the spinner and not the UpDown portion like the Win32 Spinner.
                    IntPtr hwndParent = NativeMethodsSetLastError.GetAncestor(hwnd, NativeMethods.GA_PARENT);
                    if (hwndParent != IntPtr.Zero)
                    {
                        // Test for spinner - Create checks if the element is a spinner
                        ProxySimple spinner = (ProxySimple)WinformsSpinner.Create(hwndParent, 0);
                        if (spinner != null)
                        {
                            el = spinner;
                        }
                    }
                }

                el.DispatchEvents(eventId, idProp, idObject, idChild);
            }
        }
Example #2
0
        // Sets the text of the edit part of the Combo
        void IValueProvider.SetValue(string str)
        {
            // Ensure that the window and all its parents are enabled.
            Misc.CheckEnabled(_hwnd);

            // piggy-back on win32editbox proxy
            NativeMethods.COMBOBOXINFO cbInfo = new NativeMethods.COMBOBOXINFO(NativeMethods.comboboxInfoSize);

            if (GetComboInfo(_hwnd, ref cbInfo) && SafeNativeMethods.IsWindowVisible(cbInfo.hwndItem))
            {
                WindowsEditBox editBox       = new WindowsEditBox(cbInfo.hwndItem, null, -1);
                IValueProvider valueProvider = (IValueProvider)editBox.GetPatternProvider(ValuePattern.Pattern);

                // try to set user-provided text
                valueProvider.SetValue(str);

                // Let the parent know that the value has change, to allow the parent to do any processing it needs
                // to do on value change.
                IntPtr hwndParent = Misc.GetParent(_hwnd);
                if (hwndParent != IntPtr.Zero)
                {
                    int    id     = Misc.GetWindowId(_hwnd);
                    IntPtr wParam = new IntPtr(NativeMethods.Util.MAKELONG(id, NativeMethods.CBN_EDITUPDATE));

                    Misc.ProxySendMessage(hwndParent, NativeMethods.WM_COMMAND, wParam, _hwnd);
                }

                return;
            }

            throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
        }
        // ------------------------------------------------------
        //
        // Constructors
        //
        // ------------------------------------------------------

        #region Constructors 

        // Contructor for WindownsSpinner class. Calls the base class constructor.
        internal WindowsSpinner(IntPtr hwndUpDown, IntPtr hwndEdit, ProxyFragment parent, int item)
            : base(hwndUpDown, parent, item)
        {
            _elEdit = new WindowsEditBox(hwndEdit, this, 0);
            _elUpDown = new WindowsUpDown(hwndUpDown, this, 0);

            // Set the strings to return properly the properties.
            _cControlType = ControlType.Spinner;

            // support for events
            _createOnEvent = new WinEventTracker.ProxyRaiseEvents(RaiseEvents);
        }
Example #4
0
        // ------------------------------------------------------
        //
        // Constructors
        //
        // ------------------------------------------------------

        #region Constructors

        // Contructor for WindownsSpinner class. Calls the base class constructor.
        internal WindowsSpinner(IntPtr hwndUpDown, IntPtr hwndEdit, ProxyFragment parent, int item)
            : base(hwndUpDown, parent, item)
        {
            _elEdit   = new WindowsEditBox(hwndEdit, this, 0);
            _elUpDown = new WindowsUpDown(hwndUpDown, this, 0);

            // Set the strings to return properly the properties.
            _cControlType = ControlType.Spinner;

            // support for events
            _createOnEvent = new WinEventTracker.ProxyRaiseEvents(RaiseEvents);
        }
        //------------------------------------------------------
        //
        //  Constructor
        //
        //------------------------------------------------------
 
        internal WindowsEditBoxRange(WindowsEditBox provider, int start, int end)
        {
            if (start < 0 || end < start)
            {
                // i'm throwing an invalid operation exception rather than an argument exception because 
                // clients never call this constructor directly.  it always happens as a result of some 
                // other operation, e.g. cloning an existing TextPatternRange.
                throw new InvalidOperationException(SR.Get(SRID.InvalidTextRangeOffset,GetType().FullName));
            }
            Debug.Assert(provider != null);

            _provider = provider;
            _start = start;
            _end = end;
        }
        //------------------------------------------------------
        //
        //  Constructor
        //
        //------------------------------------------------------

        internal WindowsEditBoxRange(WindowsEditBox provider, int start, int end)
        {
            if (start < 0 || end < start)
            {
                // i'm throwing an invalid operation exception rather than an argument exception because
                // clients never call this constructor directly.  it always happens as a result of some
                // other operation, e.g. cloning an existing TextPatternRange.
                throw new InvalidOperationException(SR.Get(SRID.InvalidTextRangeOffset, GetType().FullName));
            }
            Debug.Assert(provider != null);

            _provider = provider;
            _start    = start;
            _end      = end;
        }
        // ------------------------------------------------------
        //
        // Constructors
        //
        // ------------------------------------------------------

        #region Constructors

        WindowsRichEdit(IntPtr hwnd, ProxyFragment parent, int style)
            : base(hwnd, parent, style)
        {
            _type = WindowsEditBox.GetEditboxtype(hwnd);
            if (IsMultiline)
            {
                _cControlType = ControlType.Document;
            }
            else
            {
                _cControlType = ControlType.Edit;
            }

            _fIsKeyboardFocusable = true;

            // support for events
            _createOnEvent = new WinEventTracker.ProxyRaiseEvents(RaiseEvents);
        }
        internal static void SetValue (string val, IntPtr hwnd, int item)
        {
            // PerSharp/PreFast will flag this as warning 6507/56507: Prefer 'string.IsNullOrEmpty(val)' over checks for null and/or emptiness.
            // An empty strings is valued here, while a null string is not.
            // Therefore we can not use IsNullOrEmpty() here, suppress the warning.
#pragma warning suppress 6507
            if (val == null)
            {
                throw new ArgumentNullException ("val");
            }

            if (!WindowsListView.ListViewEditable (hwnd))
            {
                throw new InvalidOperationException(SR.Get(SRID.ValueReadonly));
            }

            Misc.SetFocus(hwnd);

            // set focus to the item
            WindowsListView.SetItemFocused (hwnd, item);

            // retrieve edit window
            IntPtr hwndEdit = WindowsListView.ListViewEditLabel (hwnd, item);

            if (IntPtr.Zero == hwndEdit)
            {
                throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
            }

            // re-use editbox proxy to do the job
            // Note: we will pass null and -1 for some of the parameters
            // this is ok, since the only thing that matters to us is an ability to set the text
            // and these parameters irrelevant for our task
            WindowsEditBox editBox = new WindowsEditBox (hwndEdit, null, -1);

            // get value pattern
            IValueProvider valueProvider = editBox.GetPatternProvider (ValuePattern.Pattern) as IValueProvider;

            // try to set user-provided text
            bool setValueSucceeded = false;
            try
            {
                valueProvider.SetValue (val);
                setValueSucceeded = true;
            }
            finally
            {
                // even if there is a problem doing SetValue need to exit
                // editing mode (e.g. cleanup from editing mode).
                FinishEditing(setValueSucceeded, hwnd, hwndEdit);
            }

            // Need to give some time for the control to do all its processing.
            bool wasTextSet = false;
            for (int i = 0; i < 10; i++)
            {
                System.Threading.Thread.Sleep(1);

                // Now see if the item really got set.
                if (val.Equals(ListViewItem.GetText(hwnd, item, 0)))
                {
                    wasTextSet = true;
                    break;
                }
            }
            if (!wasTextSet)
            {
                throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
            }

        }
        // ------------------------------------------------------
        //
        // Constructors
        //
        // ------------------------------------------------------

        #region Constructors

        // Contructor for WinformsSpinner class. Calls the base class constructor.
        internal WinformsSpinner(IntPtr hwnd, IntPtr hwndEdit, IntPtr hwndUpDown, ProxyFragment parent, int item)
            : base(hwnd, parent, item)
        {
            _elEdit   = new WindowsEditBox(hwndEdit, this, (int)0);
            _elUpDown = new WindowsUpDown(hwndUpDown, this, (int)0);

            string text;

            try
            {
                text = Misc.ProxyGetText(hwndEdit);
            }
            catch (TimeoutException)
            {
                text = null;
            }
            catch (Win32Exception)
            {
                text = null;
            }

            if (!string.IsNullOrEmpty(text))
            {
                try
                {
                    double.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture);

                    // the text parsed just fine so must be a number.
                    _type = SpinnerType.Numeric;
                }
                catch (FormatException)
                {
                    // the text is not a based 10 number.  Check if the text is a hex number.
                    try
                    {
                        int.Parse(text, NumberStyles.HexNumber, CultureInfo.InvariantCulture);

                        // the text parsed just fine so must be a number.
                        _type = SpinnerType.Numeric;
                    }
                    catch (FormatException)
                    {
                        // the text does not consist solely of an optional negative sign followed by a sequence of
                        // digits ranging from 0 to 9, so this spinner must be a domain spinner
                        _type = SpinnerType.Domain;
                    }
                    catch (OverflowException)
                    {
                        // the text represents a number less than MinValue or greater than MaxValue, but it is still
                        // a number, therefore must be a numeric spinner
                        _type = SpinnerType.Numeric;
                    }
                }
                catch (OverflowException)
                {
                    // the text represents a number less than MinValue or greater than MaxValue, but it is still
                    // a number, therefore must be a numeric spinner
                    _type = SpinnerType.Numeric;
                }
            }
            else
            {
                // numeric spinners always have a value.  The defualt state of a domain spinner
                // may be blank.  The text value is blank so this must be a domain spinner.
                _type = SpinnerType.Domain;
            }

            // Set the strings to return properly the properties.
            _cControlType = ControlType.Spinner;

            // support for events
            _createOnEvent = new WinEventTracker.ProxyRaiseEvents(WindowsUpDown.RaiseEvents);
        }
        internal static void SetValue(string val, IntPtr hwnd, int item)
        {
            // PerSharp/PreFast will flag this as warning 6507/56507: Prefer 'string.IsNullOrEmpty(val)' over checks for null and/or emptiness.
            // An empty strings is valued here, while a null string is not.
            // Therefore we can not use IsNullOrEmpty() here, suppress the warning.
#pragma warning suppress 6507
            if (val == null)
            {
                throw new ArgumentNullException("val");
            }

            if (!WindowsListView.ListViewEditable(hwnd))
            {
                throw new InvalidOperationException(SR.Get(SRID.ValueReadonly));
            }

            Misc.SetFocus(hwnd);

            // set focus to the item
            WindowsListView.SetItemFocused(hwnd, item);

            // retrieve edit window
            IntPtr hwndEdit = WindowsListView.ListViewEditLabel(hwnd, item);

            if (IntPtr.Zero == hwndEdit)
            {
                throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
            }

            // re-use editbox proxy to do the job
            // Note: we will pass null and -1 for some of the parameters
            // this is ok, since the only thing that matters to us is an ability to set the text
            // and these parameters irrelevant for our task
            WindowsEditBox editBox = new WindowsEditBox(hwndEdit, null, -1);

            // get value pattern
            IValueProvider valueProvider = editBox.GetPatternProvider(ValuePattern.Pattern) as IValueProvider;

            // try to set user-provided text
            bool setValueSucceeded = false;
            try
            {
                valueProvider.SetValue(val);
                setValueSucceeded = true;
            }
            finally
            {
                // even if there is a problem doing SetValue need to exit
                // editing mode (e.g. cleanup from editing mode).
                FinishEditing(setValueSucceeded, hwnd, hwndEdit);
            }

            // Need to give some time for the control to do all its processing.
            bool wasTextSet = false;
            for (int i = 0; i < 10; i++)
            {
                System.Threading.Thread.Sleep(1);

                // Now see if the item really got set.
                if (val.Equals(ListViewItem.GetText(hwnd, item, 0)))
                {
                    wasTextSet = true;
                    break;
                }
            }
            if (!wasTextSet)
            {
                throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
            }
        }
Example #11
0
        // Static Create method called by the event tracker system
        internal static void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int idObject, int idChild)
        {
            if (idObject != NativeMethods.OBJID_VSCROLL && idObject != NativeMethods.OBJID_HSCROLL)
            {
                ProxySimple el;
                if (IsInsideOfIPAddress(hwnd))
                {
                    el = new ByteEditBoxOverride(hwnd, idChild);
                }
                else
                {
                    el = new WindowsEditBox(hwnd, null, 0);

                    // If this is an Edit control inside of a [....] Spinner, need to treat the property
                    // changes for as property changes on the whole [....] Spinner, not on the element
                    // of the [....] Spinner.  [....] Spinner raise WinEvents on the Edit portion of
                    // the spinner and not the UpDown portion like the Win32 Spinner.
                    IntPtr hwndParent = NativeMethodsSetLastError.GetAncestor(hwnd, NativeMethods.GA_PARENT);
                    if (hwndParent != IntPtr.Zero)
                    {
                        // Test for spinner - Create checks if the element is a spinner
                        ProxySimple spinner = (ProxySimple)WinformsSpinner.Create(hwndParent, 0);
                        if (spinner != null)
                        {
                            el = spinner;
                        }
                    }
                }

                el.DispatchEvents (eventId, idProp, idObject, idChild);
            }
        }
Example #12
0
        // ------------------------------------------------------
        //
        // Constructors
        //
        // ------------------------------------------------------

        #region Constructors 

        // Contructor for WinformsSpinner class. Calls the base class constructor.
        internal WinformsSpinner(IntPtr hwnd, IntPtr hwndEdit, IntPtr hwndUpDown, ProxyFragment parent, int item)
            : base(hwnd, parent, item)
        {
            _elEdit = new WindowsEditBox(hwndEdit, this, (int)0);
            _elUpDown = new WindowsUpDown(hwndUpDown, this, (int)0);

            string text;
            try
            {
                text = Misc.ProxyGetText(hwndEdit);
            }
            catch (TimeoutException)
            {
                text = null;
            }
            catch (Win32Exception)
            {
                text = null;
            }

            if (!string.IsNullOrEmpty(text))
            {
                try
                {
                    double.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture);

                    // the text parsed just fine so must be a number.
                    _type = SpinnerType.Numeric;
                }
                catch (FormatException)
                {
                    // the text is not a based 10 number.  Check if the text is a hex number.
                    try
                    {
                        int.Parse(text, NumberStyles.HexNumber, CultureInfo.InvariantCulture);

                        // the text parsed just fine so must be a number.
                        _type = SpinnerType.Numeric;
                    }
                    catch (FormatException)
                    {
                        // the text does not consist solely of an optional negative sign followed by a sequence of
                        // digits ranging from 0 to 9, so this spinner must be a domain spinner
                        _type = SpinnerType.Domain;
                    }
                    catch (OverflowException)
                    {
                        // the text represents a number less than MinValue or greater than MaxValue, but it is still
                        // a number, therefore must be a numeric spinner
                        _type = SpinnerType.Numeric;
                    }
                }
                catch (OverflowException)
                {
                    // the text represents a number less than MinValue or greater than MaxValue, but it is still
                    // a number, therefore must be a numeric spinner
                    _type = SpinnerType.Numeric;
                }
            }
            else
            {
                // numeric spinners always have a value.  The defualt state of a domain spinner
                // may be blank.  The text value is blank so this must be a domain spinner.
                _type = SpinnerType.Domain;
            }

            // Set the strings to return properly the properties.
            _cControlType = ControlType.Spinner;

            // support for events
            _createOnEvent = new WinEventTracker.ProxyRaiseEvents(WindowsUpDown.RaiseEvents);
        }
Example #13
0
        // Sets the text of the edit part of the Combo
        void IValueProvider.SetValue (string str)
        {
            // Ensure that the window and all its parents are enabled.
            Misc.CheckEnabled(_hwnd);

            // piggy-back on win32editbox proxy
            NativeMethods.COMBOBOXINFO cbInfo = new NativeMethods.COMBOBOXINFO(NativeMethods.comboboxInfoSize);

            if (GetComboInfo(_hwnd, ref cbInfo) && SafeNativeMethods.IsWindowVisible(cbInfo.hwndItem))
            {
                WindowsEditBox editBox = new WindowsEditBox(cbInfo.hwndItem, null, -1);
                IValueProvider valueProvider = (IValueProvider) editBox.GetPatternProvider (ValuePattern.Pattern);

                // try to set user-provided text
                valueProvider.SetValue (str);

                // Let the parent know that the value has change, to allow the parent to do any processing it needs
                // to do on value change.
                IntPtr hwndParent = Misc.GetParent(_hwnd);
                if (hwndParent != IntPtr.Zero)
                {
                    int id = Misc.GetWindowId(_hwnd);
                    IntPtr wParam = new IntPtr(NativeMethods.Util.MAKELONG(id, NativeMethods.CBN_EDITUPDATE));

                    Misc.ProxySendMessage(hwndParent, NativeMethods.WM_COMMAND, wParam, _hwnd);
                }

                return;
            }

            throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
        }