// ------------------------------------------------------ // // 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); }
// Called by the event tracker system. internal static void RaiseEvents(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild) { if (idObject == NativeMethods.OBJID_CLIENT && eventId == NativeMethods.EventObjectInvoke && idProp == InvokePattern.InvokedEvent) { RaiseInvokedEvent(hwnd, idObject, idChild); } else if (idObject != NativeMethods.OBJID_VSCROLL && idObject != NativeMethods.OBJID_HSCROLL) { WindowsUpDown wtv = new WindowsUpDown(hwnd, null, -1); wtv.DispatchEvents(eventId, idProp, idObject, idChild); } }
// Static Create method called by UIAutomation to create proxies for [....] controls. // returns null if unsuccessful internal static IRawElementProviderSimple Create(IntPtr hwnd, int idChild, int idObject) { // Currently there is an issue with CLR remoting that causes Accessible.CreateNativeFromEvent() to fail // for [....] controls. Until that is resolved use AccessibleObjectFromWindow() instead. It will // return a Native IAccessble and not a OleAcc implementaion. [....] does provide a Native IAccessible. Accessible acc = null; if (Accessible.AccessibleObjectFromWindow(hwnd, idObject, ref acc) != NativeMethods.S_OK || acc == null) { return(null); } switch (acc.Role) { // ============================================================ // WinformsSpinner controls are not identifiable by classname or // other simple properties. The following case calls the // WinformsSpinner constructor which in turn tries to establish // the class of the control as a fact or returns null. case AccessibleRole.Combobox: return(WinformsSpinner.Create(hwnd, idChild, idObject)); // ============================================================ case AccessibleRole.SpinButton: return(WindowsUpDown.Create(hwnd, idChild, idObject)); case AccessibleRole.Grouping: return(new WindowsButton(hwnd, null, WindowsButton.ButtonType.GroupBox, Misc.GetWindowStyle(hwnd) & NativeMethods.BS_TYPEMASK, acc)); case AccessibleRole.StatusBar: WindowsStatusBar sb = new WindowsStatusBar(hwnd, null, 0, acc); if (sb == null) { return(null); } return(idChild == NativeMethods.CHILD_SELF ? sb : sb.CreateStatusBarPane(idChild)); default: break; } return(null); }
private static void RaiseInvokedEvent(IntPtr hwnd, int idObject, int idChild) { ProxySimple button = null; if (idChild == 1) { WindowsUpDown wtv = new WindowsUpDown(hwnd, null, -1); button = wtv.CreateSpinButtonItem(SpinItem.DownArrow); } else if (idChild == 2) { WindowsUpDown wtv = new WindowsUpDown(hwnd, null, -1); button = wtv.CreateSpinButtonItem(SpinItem.UpArrow); } if (button != null) { button.DispatchEvents(NativeMethods.EventObjectInvoke, InvokePattern.InvokedEvent, idObject, idChild); } }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors // Contructor for SpinControlProxy class. Calls the base class constructor. internal SpinButtonItem(IntPtr hwnd, ProxyFragment parent, int item) : base(hwnd, parent, item) { // Set the strings to return properly the properties. _fIsContent = false; _cControlType = ControlType.Button; WindowsUpDown upDownParent = parent as WindowsUpDown; if (upDownParent != null) { _isInsideOfTab = upDownParent.IsInsideOfTab(); } // The buttons are swapped on a tab control compared to the spinner. if (_isInsideOfTab) { item = 1 - item; } _sAutomationId = _asAutomationId[item]; }
// ------------------------------------------------------ // // 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); }
// Called by the event tracker system. internal static void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int idObject, int idChild) { if(idObject == NativeMethods.OBJID_CLIENT && eventId == NativeMethods.EventObjectInvoke && idProp == InvokePattern.InvokedEvent) { RaiseInvokedEvent(hwnd, idObject, idChild); } else if (idObject != NativeMethods.OBJID_VSCROLL && idObject != NativeMethods.OBJID_HSCROLL) { WindowsUpDown wtv = new WindowsUpDown (hwnd, null, -1); wtv.DispatchEvents (eventId, idProp, idObject, idChild); } }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods static internal Rect GetBoundingRectangle(IntPtr hwnd, WindowsUpDown.SpinItem item) { NativeMethods.Win32Rect updownRect = new NativeMethods.Win32Rect(); if (!Misc.GetWindowRect(hwnd, ref updownRect)) { return Rect.Empty; } bool fHorz = IsHorizontal(hwnd); // If the control is horizontal and the WS_EX_LAYOUTRTL is set need to // swap the button order if (fHorz && Misc.IsLayoutRTL(hwnd)) { item = item == SpinItem.DownArrow ? SpinItem.UpArrow : SpinItem.DownArrow; } switch (item) { case WindowsUpDown.SpinItem.DownArrow: if (fHorz) { int width = (updownRect.right - updownRect.left); updownRect.right = updownRect.left + width / 2; } else { int height = (updownRect.bottom - updownRect.top); updownRect.bottom = updownRect.top + height / 2; } // Don't need to normalize, GetWindowRect returns screen coordinates. return updownRect.ToRect(false); case WindowsUpDown.SpinItem.UpArrow: if (fHorz) { int width = (updownRect.right - updownRect.left); updownRect.left = updownRect.left + width / 2; } else { int height = (updownRect.bottom - updownRect.top); updownRect.top = updownRect.top + height / 2; } // Don't need to normalize, GetWindowRect returns screen coordinates. return updownRect.ToRect(false); } return Rect.Empty; }